package cn.tedu.sp04.feign;

import cn.tedu.sp01.pojo.Item;
import cn.tedu.web.util.JsonResult;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
@Component
public class ItemServiceFB implements ItemClient {
    @Override
    public JsonResult<List<Item>> getItems(String orderId) {
        //模拟有缓存数据
        if(Math.random()>0.5){
            ArrayList<Item> list = new ArrayList<>();
            list.add(new Item(1,"缓",5));
            list.add(new Item(2,"存",4));
            list.add(new Item(3,"商",3));
            list.add(new Item(4,"品",2));
            list.add(new Item(5,"啊",1));
            return JsonResult.ok().data(list);
        }
        //有缓存时返回缓存数据，没有缓存时返回错误提示
        return JsonResult.err().msg("获取订单的商品列表失败");


    }

    @Override
    public JsonResult<?> decreasaNumber(List<Item> items) {
        return JsonResult.err().msg("减少商品库存失败");
    }
}
